package com.wonder.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public class MapToEntity {
    public static <T> T mapToBean(Map<String, Object> map, Class<T> clazz) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mapper.setDateFormat(dateFormat);
        return mapper.convertValue(map, clazz);
    }

    /**
     * 实体类转map
     * @param obj
     * @return
     */
    public static Map<String, Object> objectToMap(Object obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String,Object> map = objectMapper.convertValue(obj,Map.class);
        return map;
    }

}
